<?php
require_once "header.php";

$myyw = new myyahooWeather();

if (!empty($xoopsModuleConfig['use_cache'])) {
    $myyw->cache_setting($xoopsModuleConfig['cache_time']);
} 

$xoopsOption['template_main'] = 'tenki_index.html';
include XOOPS_ROOT_PATH . "/header.php";

if (isset($_COOKIE['xoops_tenki'])) {
    // $xoopsTpl->register_object("myyw", $myyw);
    xoops_tenki_resetcookie();
    list($area_id, $pinpoint_id) = explode(",", $_COOKIE['xoops_tenki']);
    $myyw->setArea(intval($area_id));
    if (!empty($pinpoint_id)) {
        $xoopsTpl->assign("my_area", 2);
        $myyw->setpArea(intval($pinpoint_id));
        $xoopsTpl->assign($myyw->area_pinfo);

        $xoopsTpl->assign('today', xoops_tenki_convert2image_local($myyw->getVal('today', 1)));
        $xoopsTpl->assign('tomorrow', xoops_tenki_convert2image_local($myyw->getVal('tomorrow', 1)));
        $weekly = xoops_tenki_convert2image_weekly($myyw->getVal('weekly', 1));
        foreach($weekly as $val) {
            $xoopsTpl->append('weekly', $val);
        } 
    } else {
        $xoopsTpl->assign("my_area", 1);
        $xoopsTpl->assign($myyw->area_info);

        $xoopsTpl->assign('today', xoops_tenki_convert2image_area($myyw->getVal('today')));
        $xoopsTpl->assign('tomorrow', xoops_tenki_convert2image_area($myyw->getVal('tomorrow')));
        $weekly = xoops_tenki_convert2image_weekly($myyw->getVal('weekly'));
        foreach($weekly as $val) {
            $xoopsTpl->append('weekly', $val);
        } 
    } 
} 

foreach($myyw->areadata as $val) {
    $xoopsTpl->append($val['prefecture_key'], $val);
} 
include XOOPS_ROOT_PATH . "/footer.php";

?>